#!/bin/bash
echo -e  "\e[32m=======开始安装mysql========\e[0m"
if ! docker images | grep "mysql.*5.7.*" &>/dev/null
then
	
	echo -e  "\e[33m=======开始拉取mysql镜像========\e[0m"
	docker pull mysql:5.7
	echo -e  "\e[33m=======镜像拉取完成========\e[0m"
fi
if docker ps -a | grep "mysql$" &>/dev/null
then
	docker rm -f  mysql &>/dev/null
fi
docker run -p 3306:3306 --name=mysql --restart=always \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7 &>/dev/null
if ! [ -f /mydata/mysql/conf/my.conf ]
then
touch /mydata/mysql/conf/my.conf
cat >/mydata/mysql/conf/my.conf << EOF
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
init_connect='SET collation_connection=utf8_unicode_ci'
init_connect="SET NAMES utf8"
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
EOF
docker restart mysql>/dev/null
fi
echo -e "\e[32m======mysql安装完成========\e[0m"
